Back to course home
0% completed
Vote For New Content
Google Hard
Shortest Subarray with Sum at Least K (hard)
Solution: Shortest Subarray with Sum at Least K
Reverse Pairs (hard)
Solution: Reverse Pairs
Nth Magical Number (hard)
Solution: Nth Magical Number
Candy (hard)
Solution: Candy
Arithmetic Slices II - Subsequence (hard)
Solution: Arithmetic Slices II - Subsequence
Burst Balloons (hard)
Solution: Burst Balloons
Sum of Distances in Tree (hard)
Solution: Sum of Distances in Tree
Maximum Score of a Good Subarray (hard)
Solution: Maximum Score of a Good Subarray
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
Maximum Length of Semi-Decreasing Subarrays (medium)
Problem Statement
Given an integer array nums, return the length of the longest semi-decreasing subarray of nums, or 0 if there are no such subarrays.
If the first element is strictly greater than its last element for any array, it is semi-decreasing.
A subarray is a contiguous non-empty sequence of elements within an array.
Examples
-
Example 1:
- Input: nums =
[8, 4, 5, 3, 2] - Expected Output:
5 - Justification: The entire array is the largest segment where the first element (8) is greater than the last (2).
- Input: nums =
-
Example 2:
- Input: nums =
[1, 2, 3, 4, 5] - Expected Output:
0 - Justification: There's no segment where the starting number is greater than the ending number.
- Input: nums =
-
Example 3:
- Input: nums =
[1, 2, 12, 2, 5, 11, 13] - Expected Output:
4 - Justification: The largest semi-decreasing subarray is [12, 2, 5, 11].
- Input: nums =
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Strobogrammatic Number II
Solution: Maximum Length of Semi-Decreasing Subarrays
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself